<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[{ name: 'box-base', title: '基础信息' },{ name: 'box-info', title: '就诊信息' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="姓名" name="name" :parent="_self" :form="form" />
          <customFormItem
            label="性别"
            name="gender"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: utils.getDictDataList(constCommon.dictType.commonGender) }"
          />
          <customFormItem label="身份证号" name="idCode" :parent="_self" :form="form" />
          <customFormItem label="年龄" name="age" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name" />
          <div id="box-info" class="box-title">就诊信息</div>
          <customFormItem label="病案号" name="no" :parent="_self" :form="form" />
          <customFormItem
            label="病人类型"
            name="type"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: utils.getDictDataList(constCommon.dictType.patientType) }"
          />
          <customFormItem label="住院号" name="inpatientNo" :parent="_self" :form="form" v-show="form.type == '0'" />
          <customFormItem
            label="住院流水号"
            name="inpatientSn"
            :parent="_self"
            :form="form"
            v-show="form.type == '0'"
          />
          <customFormItem label="门诊号" name="outpatientNo" :parent="_self" :form="form" v-show="form.type == '1'" />
          <customFormItem
            label="门诊流水号"
            name="outpatientSn"
            :parent="_self"
            :form="form"
            v-show="form.type == '1'"
          />
          <customFormItem
            label="住院科室"
            name="inDeptName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(selectChange)"
            v-show="form.type == '0'"
          />

          <customFormItem
            label="门诊科室"
            name="outDeptName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(selectChange)"
            v-show="form.type == '1'"
          />
          <customFormItem label="床位号" name="bedNo" :parent="_self" :form="form" />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
     //下拉列表选择后
    selectChange(row) {
      const type = this.form.type
      if (type == '0') {
        this.$set(this.form, 'inDeptCode', row.id)
        this.$set(this.form, 'inDeptName', row.name)
      }
      if (type == '1') {
        this.$set(this.form, 'outDeptCode', row.id)
        this.$set(this.form, 'outDeptName', row.name)
      }
    },
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        // 新增，设置默认值
        if (!this.form.id) {
          this.$set(this.form, 'type', '0')
        }
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: () => {
        return true
      },
      afterFlow: () => {},
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: {
    customAnchor,
  },
  computed: {},
}
</script>
